﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using X.Web;

namespace X.WebSite.Admin.Product
{
    public partial class CategoryList : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }

        private void BindGrid()
        {
            gvCategoryList.DataSource = Bll.ProductCategory.GetList();
            gvCategoryList.DataBind();
        }

        protected void gvCategoryList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int categoryId = Convert.ToInt32(gvCategoryList.DataKeys[e.RowIndex].Value);

            if (Bll.ProductCategory.GetProductCount(categoryId) > 0)
            {
                Response.Write("<script>alert(\"该产品类别下还有产品,不能删除!\");</script>");
            }
            else
            {
                Bll.ProductCategory.Delete(categoryId);

                BindGrid();
            }
        }
    }
}